package com.systemdevelopment.mainproject.View.NormalUser;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import com.jfoenix.controls.JFXTextField;
import com.systemdevelopment.mainproject.Model.Book;
import com.systemdevelopment.mainproject.Model.BorrowRecord;
import com.systemdevelopment.mainproject.Model.Record;
import com.systemdevelopment.mainproject.View.Visitor.bookPane;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Pagination;
import javafx.scene.control.TextFormatter;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import com.systemdevelopment.mainproject.View.mainUI;
import javax.lang.model.type.ArrayType;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;

public class UserRecordController {



    @FXML
    private Pagination pagination;





    public UserRecordController() throws SQLException {
        pagination=new Pagination();
        ArrayList<recordPane> recordPanes=new ArrayList<>();
        ArrayList<Record> records=BorrowRecord.getReaderRecord(mainUI.userController.getUser().getAccount());
        for(Record record:records)
        {
            recordPanes.add(new recordPane(record));
        }
        int size=recordPanes.size();

        pagination.setMaxPageIndicatorCount(size/3+1);
        pagination.setPageCount(size/3+1);
        pagination.setPageFactory(param -> {
            VBox pane=new VBox();
            pane.setPrefHeight(450);
            pane.setPrefWidth(700);
            HBox fristBox=new HBox();
            HBox secondBox=new HBox();
            HBox thirdBox=new HBox();
            fristBox.setPrefHeight(150);
            fristBox.setPrefWidth(700);
            secondBox.setPrefWidth(700);
            secondBox.setPrefHeight(150);
            thirdBox.setPrefWidth(700);
            thirdBox.setPrefHeight(150);

            fristBox.getChildren().add(recordPanes.get(param*3).getPane());


            secondBox.getChildren().add(recordPanes.get(param*3+1).getPane());
            thirdBox.getChildren().add(recordPanes.get(param*3+2).getPane());
            pane.getChildren().add(fristBox);
            pane.getChildren().add(secondBox);
            pane.getChildren().add(thirdBox);
            return pane;
        });

        pagination.setVisible(true);

    }
}
